﻿<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
     style="padding: 20px 30px 0 0;">

    <script type='text/html' template lay-done='layui.data.formdone(d.params);'>
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}" />
    </script>
    <div class='layui-form-item'>
        <label class='layui-form-label'>广告类型<label style="color: red">*</label></label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <select name='Mode' lay-verify='required' lay-filter="selmode">
                    <option value=""></option>
                    <option value='0' {{ d.params.Mode == '0' ? 'selected' : '' }}>加载广告</option>
                    <option value='1' {{ d.params.Mode == '1' ? 'selected' : '' }}>开屏广告</option>
                    <option value='2' {{ d.params.Mode == '2' ? 'selected' : '' }}>头部轮播</option>
                    <option value='3' {{ d.params.Mode == '3' ? 'selected' : '' }}>类别广告</option>
                </select>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>所属分类<span style="color:red">*</span></label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"GoodsCategoryID_SelSource");'>
                  <select name="GoodsCategoryID_SelSource" id="GoodsCategoryID_SelSource" xm-select="GoodsCategoryID_SelSource" lay-verify='required' xm-select-radio="" xm-select-search xm-select-skin="default">
                    <option value=""></option>
                </select>
            </script>
        </div>
     
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>广告标题<label style="color: red">*</label></label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <input type='text' name='Title' value='{{ d.params.Title || '' }}' lay-verify='required' placeholder='广告标题' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>广告封面<span style="color:red">*</span></label>
        <div class='layui-input-inline' style="width:80%">
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="selectImg">选择图片</button> <span id="imgsp">建议尺寸 750px * 320px</span>
                <div class="layui-upload-list" id="divImgs"></div>
                <script type='text/html' template lay-done='layui.data.setUploads(d.params);'>
                    <input type="hidden" name="Logo_Upload" id="Logo_Upload" value="{{ d.params.Logo_Upload || '' }}">
                </script>
                <hr />
            </div>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>跳转类型 </label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <select name='Type_Sel' lay-filter='Type_Sel'>
                    <option value="-1">请选择</option>
                    <option value='0' {{ d.params.Type_Sel == '0' ? 'selected' : '' }}>主题商品</option>
                    <option value='1' {{ d.params.Type_Sel == '1' ? 'selected' : '' }}>商品详情</option>
                    <option value='9' {{ d.params.Type_Sel == '9' ? 'selected' : '' }}>页面链接</option>
                </select>
            </script>
        </div>
    </div>

    <div class='layui-form-item' id='divthemeType'>
        <label class='layui-form-label'>指定主题</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"themeType");'>
                <select name="themeType" id="themeType" xm-select="themeType" xm-select-search="" xm-select-radio="" xm-select-skin="default">
                    <option value=""></option>
                </select>
            </script>
        </div>
    </div>

    <div class='layui-form-item' id='divgoodXh'>
        <label class='layui-form-label'>商品编号</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <input type='text' id='goodXh' name='goodXh' placeholder='商品编号' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>


    <div class='layui-form-item' id='divpageType'>
        <label class='layui-form-label'>页面选择</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <select name='pageType' id='pageType'>
                    <option value=""></option>
                    <option value='0'>优惠券</option>
                    <option value='1'>商品列表</option>
                </select>
            </script>
        </div>
    </div>



    <div class='layui-form-item'>
        <label class='layui-form-label'>开始时间 <label style="color: red">*</label></label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template lay-done='layui.data.datedone(d.params);'>
                <input type='text' name='StartTime' readonly='readonly' id='StartTime' value='{{ d.params.StartTime || '' }}' lay-verify='datetime' placeholder='yyyy-MM-dd HH:mm:ss' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>结束时间 <label style="color: red">*</label></label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template lay-done='layui.data.datedone(d.params);'>
                <input type='text' name='EndTime' readonly='readonly' id='EndTime' value='{{ d.params.EndTime || '' }}' lay-verify='datetime' placeholder='yyyy-MM-dd HH:mm:ss' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>描述</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <input type='text' name='Description' value='{{ d.params.Description || '' }}' lay-verify='' placeholder='描述' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>是否启用</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <select name='IsAble' lay-filter='IsAble'>
                    <option value='0' {{ d.params.IsAble == '0' ? 'selected' : '' }}>启用</option>
                    <option value='1' {{ d.params.IsAble == '1' ? 'selected' : '' }}>停用</option>
                </select>
            </script>
        </div>
    </div>

    <!--<div class='layui-form-item'>
        <label class='layui-form-label'>店铺ID</label>
        <div class='layui-input-inline'>
            <script type='text/html' template>
                <input type='text' name='StoreID' value='{{ d.params.StoreID || '' }}' lay-verify='required' placeholder='店铺ID' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>
<style>
    .layui-upload-img {
        width: 100px;
        height: auto;
    }
</style>

<script type="text/javascript">

    //layui.use(['form', 'admin'], function () {
    //    var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
    //    var admin = layui.admin;
    //    var $ = layui.$;

 


    //});
    layui.data.getColor = function (d) {
        layui.use(['form', 'admin', 'colorpicker'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            var colorpicker = layui.colorpicker;

            var color = "#ffffff";
            if (d.Color != "" && d.Color != null)
                color = d.Color;
            else
                $('#Color').val(color);
            //表单赋值
            colorpicker.render({
                elem: '#test-form'
                , color: color //设置默认色
                , done: function (color) {
                    $('#Color').val(color);
                }
            });

         
        });
    }

    layui.data.setUploads = function (d) {
        layui.use(['jquery', 'upload', 'admin'], function () {
            window.jQuery = window.$ = layui.jquery;
            upload = layui.upload,
                admin = layui.admin;
            //多图上传
            var uploadInst = upload.render({
                elem: '#selectImg'
                , url: '/WebAPI/file/uploadImgNew?access_token=' + layui.data('layuiAdmin').access_token
                , acceptMime: 'image/*'
                , multiple: false
                , done: function (res) {
                    if (res.ResultCode == 0) {
                        addImg(res.Data);
                        layer.msg('上传成功');
                    } else {
                        layer.msg(res.ResultInfo);
                    }
                }
            });
            var pics = d.Logo_Upload;
            if (pics != "" && pics != null && pics != 'null') {
                addImg({ name: pics, path: layui.setter.ImgPath + pics });
            }
        })
    }

    function addImg(src) {
        var div = "divimg3";
        var img = "Img3";
        var html = "    <div style=\"line-height:100px;float:left\" id='" + div + "'> " +
            " <a style=\"float:right;line-height:10px;background-color:#ff0000;font-size:24px;color:white;border-top:3px solid #ff0000\" onclick=\"deletp3()\">×</a> " +
            " <img id='" + img + "' src=\"" + src.path + "\"   alt=\"\" class=\"layui-upload-img\">" +
            "</div>";
        $('#divImgs').html(html);
        $("#Logo_Upload").val(src.name);
    }
    //删除图片
    function deletp3() {
        $('#divImgs').html("");
        $("#Logo_Upload").val("");
    }

    layui.data.datedone = function (d) {
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#StartTime'
                , type: 'datetime'
                , calendar: true
            });
            laydate.val = d.StartTime;

            //日期时间选择器
            laydate.render({
                elem: '#EndTime'
                , type: 'datetime'
                , calendar: true
            });
            laydate.val = d.EndTime;

        });
    }

    layui.use(['form', 'admin'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
        var admin = layui.admin;
        var $ = layui.$;
        debugger
        


        $("#divthemeType").hide();
        $("#divgoodXh").hide();
        $("#divpageType").hide();
        //监听下拉框变化
        form.on('select(Type_Sel)', function (data) {
            selectChange(data.value);
        });

        form.on("select(selmode)", function (d) {
            if (d.value == 1) {
                $("#imgsp").text("建议尺寸 750px * 226px");
            } else {
                $("#imgsp").text("建议尺寸 750px * 320px");
            }
        })
      
      
    });


    function selectChange(val) {
       
            var $ = layui.$;
            if (val == 0) {
                $("#divthemeType").show();
                $("#divgoodXh").hide();
                $("#divpageType").hide();
            }

            if (val == 1) {
                $("#divthemeType").hide();
                $("#divgoodXh").show();
                $("#divpageType").hide();
            }

            if (val == 9) {
                $("#divthemeType").hide();
                $("#divgoodXh").hide();
                $("#divpageType").show();
            }
     
    }

    layui.data.formdone = function (d, sourceName) {
   
            var $ = layui.$;
            var form = layui.form;
            selectChange(d.Type_Sel);
            
            if (d.Type_Sel == 1) {
                $("#goodXh").val(d.DetailUrl);
            }

            if (d.Type_Sel == 9) {
                $("#pageType").val(d.DetailUrl);
            }

            form.render('select');

            if (d.Mode == 1) {
                $("#imgsp").text("建议尺寸 750px * 226px");
            } else {
                $("#imgsp").text("建议尺寸 750px * 320px");
            }
    }


    layui.data.getSelSource = function (d, sourceName) {
        layui.use(['admin', 'form', 'formSelects'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            var formSelects = layui.formSelects;
            var Type_Sel = d.Type_Sel;
            var content = d.DetailUrl;
            if (sourceName == "GoodsCategoryID_SelSource") {
                formSelects.config('GoodsCategoryID_SelSource', {
                    keyName: 'Name',            //自定义返回数据中name的key, 默认 name
                    keyVal: 'PID',            //自定义返回数据中value的key, 默认 value
                    keyChildren: 'children',    //联动多选自定义children
                });
                admin.req({
                    url: layui.setter.APIUrl + '/shop/GoodsCategoryMgr/customerQuery', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res1) {

                        formSelects.data('GoodsCategoryID_SelSource', 'local', {
                            arr: res1.Data
                        });
                        debugger
                        var dada = d.GoodsCategoryID_SelSource;

                        layui.formSelects.value('GoodsCategoryID_SelSource', [d.GoodsCategoryID_SelSource]);
                    }
                });

            }
            if (sourceName == 'themeType') {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/ThemeMgr/customerQuery', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res) {
                        formSelects.config('themeType', {
                            keyName: 'Name',            //自定义返回数据中name的key, 默认 name
                            keyVal: 'PID',            //自定义返回数据中value的key, 默认 value
                        });

                        layui.formSelects.data('themeType',
                            'local',
                            {
                                arr: res.Data, //要把自己的这个节点去掉
                                linkeage: false,
                                linkageWidth: 140
                            });

                        if (Type_Sel == 0 && content) {
                            if (content.indexOf(',') == -1) {
                                layui.formSelects.value('themeType', [content]);
                            } else {
                                layui.formSelects.value('themeType', content.split(','));
                            }
                        }

                    }
                });
            }

        })
    }


</script>